import os, sys

sys.path.append(os.getcwd())
from common.settings import _print
import time


def cpu_bound(number):
    _print(sum(i * i for i in range(number)))


def calculate_sums(numbers):
    import multiprocessing
    processes = []
    for number in numbers:
        p = multiprocessing.Process(target=cpu_bound, args=(number,))
        processes.append(p)
        p.start()
    for p in processes:
        p.join()


def main():
    start_time = time.perf_counter()
    numbers = [10000000 + x for x in range(20)]
    calculate_sums(numbers)
    end_time = time.perf_counter()
    _print('Calculation takes {} seconds'.format(end_time - start_time))


if __name__ == '__main__':
    main()
